package com.lxmes.device.controller;

import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.core.page.TableDataInfo;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.device.domain.DeviceFailureCheck;
import com.lxmes.device.domain.DeviceFailureRepair;
import com.lxmes.device.service.IDeviceFailureCheckService;
import com.lxmes.device.service.IDeviceFailureRepairService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备故障维修验证Controller
 * 
 * @author 张志煜
 * @date 2022-04-26
 */
@Api(tags = "故障管理-维修验证")
@RestController
@RequestMapping("/device/deviceFailureCheck")
public class DeviceFailureCheckController extends BaseController
{
    @Autowired
    private IDeviceFailureCheckService deviceFailureCheckService;
    @Autowired
    private IDeviceFailureRepairService deviceFailureRepairService;

    /**
     * 查询设备故障维修验证列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceFailureCheck:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceFailureCheck deviceFailureCheck)
    {
        startPage();
        List<DeviceFailureCheck> list = deviceFailureCheckService.selectDeviceFailureCheckList(deviceFailureCheck);
        return getDataTable(list);
    }

    /**
     * 导出设备故障维修验证列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceFailureCheck:export')")
    @Log(title = "设备故障维修验证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceFailureCheck deviceFailureCheck)
    {
        List<DeviceFailureCheck> list = deviceFailureCheckService.selectDeviceFailureCheckList(deviceFailureCheck);
        ExcelUtil<DeviceFailureCheck> util = new ExcelUtil<DeviceFailureCheck>(DeviceFailureCheck.class);
        util.exportExcel(response, list, "设备故障维修验证数据");
    }

    /**
     * 获取设备故障维修验证详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceFailureCheck:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deviceFailureCheckService.selectDeviceFailureCheckById(id));
    }
    /**
     * 通过报修单号获取设备故障维修验证详细信息
     */
    @GetMapping(value = "/getCheckInfo/{reportId}")
    public AjaxResult getCheckInfo(@PathVariable("reportId") String reportId)
    {
        return AjaxResult.success(deviceFailureCheckService.selectDeviceFailureCheckByReportId(reportId));
    }
    /**
     * 新增设备故障维修验证
     */
    @PreAuthorize("@ss.hasPermi('device:deviceFailureCheck:add')")
    @Log(title = "设备故障维修验证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceFailureCheck deviceFailureCheck)
    {
        return toAjax(deviceFailureCheckService.insertDeviceFailureCheck(deviceFailureCheck));
    }

    /**
     * 修改设备故障维修验证
     */
    @PreAuthorize("@ss.hasPermi('device:deviceFailureCheck:edit')")
    @Log(title = "设备故障维修验证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceFailureCheck deviceFailureCheck)
    {
        return toAjax(deviceFailureCheckService.updateDeviceFailureCheck(deviceFailureCheck));
    }

    /**
     * 删除设备故障维修验证
     */
    @PreAuthorize("@ss.hasPermi('device:deviceFailureCheck:remove')")
    @Log(title = "设备故障维修验证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceFailureCheckService.deleteDeviceFailureCheckByIds(ids));
    }
    /*待验证列表*/
    @ApiOperation(value="待验证列表",notes = "状态代表0待派单 1-待执行2-维修中3-待验证4-完成5-驳货")
    //查询条件
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryParams", value = "设备编码、设备名称、主修人", paramType="query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageSize", value = "分页大小",  required = true,paramType="query",  dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageNum", value = "当前页数",  required = true,paramType="query",   dataType = "int", dataTypeClass = Integer.class)
    })
    @ApiResponses({@ApiResponse(code=200,message = "0k",response = DeviceFailureRepair.class)})
    @PreAuthorize("@ss.hasPermi('mobile:repair:list3')")
    @GetMapping("/apiProgress3List")
    public TableDataInfo apiProgress3List(
            @RequestParam(value="queryParams",required = false) String queryParams)
    {
        DeviceFailureRepair deviceFailureRepair=new DeviceFailureRepair();
        deviceFailureRepair.setQueryParams(queryParams);
        deviceFailureRepair.setFaultProgress("3");
        startPage();
        List<DeviceFailureRepair> list = deviceFailureRepairService.selectApiDeviceFailureRepairProgressList(deviceFailureRepair);
        return getDataTable(list);
    }
    /**
     * 故障维修验证操作
     */
    @ApiOperation(value="故障维修验证操作",notes = "isFinish验证状态5-驳回 4-完成")
    @PreAuthorize("@ss.hasPermi('mobile:check:add')")
    @PostMapping(value = "/apiDoCheck")
    public AjaxResult apiDoCheck(@RequestBody DeviceFailureCheck deviceFailureCheck)
    {
        return toAjax(deviceFailureCheckService.apiDoCheck(deviceFailureCheck));
    }
}
